/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;
import modelo.Historial;
import dao.generic.GenericDAO;
import java.util.Iterator;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;

/**
 *
 * @author Administrador
 */
public class HistorialDAO extends GenericDAO {

    public Historial getHistorialbyId(int idHistorial) {
        Historial h = null;
        try {
            iniciarOperacion();
            h = (Historial) sesion.get(Historial.class, idHistorial);

        } finally {
            sesion.close();
        }
        return h;
    }

    public List consultaTodo() {
        List listaHis;
        try {
            iniciarOperacion();
            Query query = sesion.createQuery("FROM Historial");
            listaHis = query.list();
        } finally {
            sesion.close();
        }
        return listaHis;
    }
    public int ultimoRegistro(){
        Integer ultimo;
        try {
            iniciarOperacion();
            Query query = sesion.createQuery("SELECT MAX(id) FROM Historial");
            ultimo = (Integer)query.uniqueResult();
            if(ultimo == null)
              ultimo = 0;
            System.out.println("El ultimo fue: "+ultimo);
            
        } finally {
            sesion.close();
        }
        return ultimo;
    }
    public void consultaGasto(){
      Iterator i;
      try{
        iniciarOperacion();
        Query query = sesion.createQuery("SELECT s.");
        
      }catch(HibernateException e){
        manejarExcepcion(e);
      }
    }
}
